<style>
    .layui-form-item .layui-input-company {width: auto;padding-right: 10px;line-height: 38px;}
</style>
<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">

        <div class="layui-form layuimini-form" lay-filter="settingForm">

            <div class="layui-form-item">
                <label class="layui-form-label required">服务端口号</label>
                <div class="layui-input-block">
                    <input type="text" name="port" lay-verify="required" readonly class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">可用电量上限</label>
                <div class="layui-input-block">
                    <input type="text" name="maxPower" lay-verify="required" lay-reqtext="最大电量不能为空!" placeholder="请输入最大电量" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">可用电量下限</label>
                <div class="layui-input-block">
                    <input type="text" name="minPower" lay-verify="required" lay-reqtext="最小电量不能为空!" placeholder="请输入最小电量" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">充电可接任务电量</label>
                <div class="layui-input-block">
                    <input type="text" name="chargePower" lay-verify="required" lay-reqtext="充电可接任务电量!" placeholder="请输入最小电量" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">空闲不允许充电电量</label>
                <div class="layui-input-block">
                    <input type="text" name="idleNotChargePower" lay-verify="required" lay-reqtext="空闲不允许充电电量不能为空!低于该电量才能由空闲去充电!" placeholder="请输入空闲不允许充电电量" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">空闲等待充电时间(min)</label>
                <div class="layui-input-block">
                    <input type="text" name="idleCharginTime" lay-verify="required" lay-reqtext="空闲等待去充电时间不为空!" placeholder="请输入空闲等待去充电（min）时间，-1为不启用" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">启用电池标定</label>
                <div class="layui-input-block">
                    <input type="checkbox" name="enableCalibration" lay-verify="required" lay-skin="switch" lay-text="是|否" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">启用标定周期(min)</label>
                <div class="layui-input-block">
                    <input type="text" name="timeNode" lay-verify="required" lay-reqtext="启用标定时间节点不为空!" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">启用标定时间段开始时间</label>
                <div class="layui-input-inline">
                    <input type="datetime" name="calibrationEnableStartTime" id="calibrationEnableStartTime" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">启用标定时间段结束时间</label>
                <div class="layui-input-inline">
                    <input type="datetime" name="calibrationEnableEndTime" id="calibrationEnableEndTime" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">标定时长(min)</label>
                <div class="layui-input-block">
                    <input type="text" name="calibrationSpan" lay-verify="required" lay-reqtext="标定时长不为空!" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">上报对接状态Url</label>
                <div class="layui-input-block">
                    <input type="text" name="deliveryUrl" lay-verify="required" lay-reqtext="状态更新Url不能为空!" placeholder="请输入状态更新url" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label required">上报任务完成Url</label>
                <div class="layui-input-block">
                    <input type="text" name="completeUrl" lay-verify="required" lay-reqtext="任务完成Url不能为空!" placeholder="请输入任务完成Url" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label required">区域校验</label>
                <div class="layui-input-block">
                    <input type="checkbox" name="isRegionCheck" lay-verify="required" lay-skin="switch" lay-text="是|否" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">同位置最优送接</label>
                <div class="layui-input-block">
                    <input type="checkbox" name="isQuickMatch" lay-verify="required" lay-skin="switch" lay-text="是|否" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">物料校验</label>
                <div class="layui-input-block">
                    <input type="checkbox" name="isMaterialCheck" lay-verify="required" lay-skin="switch" lay-text="是|否" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label required">是否管控Park</label>
                <div class="layui-input-block">
                    <input type="checkbox" name="isParkControl" lay-verify="required" lay-skin="switch" lay-text="是|否" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label required">可用状态</label>
                <div class="layui-input-block">
                    <textarea name="availableStatus" class="layui-textarea"></textarea>
                    <tip>多个状态之间用,隔开</tip>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label required">是否有电梯</label>
                <div class="layui-input-block">
                    <input type="checkbox" name="hasElevator" lay-verify="required" lay-skin="switch" lay-text="是|否" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">电梯服务器IP</label>
                <div class="layui-input-block">
                    <input type="text" name="elevatorIP" placeholder="请输入电梯服务器IP" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">电梯最低层</label>
                <div class="layui-input-block">
                    <input type="number" name="elevatorLowestFloor" placeholder="请输入电梯最低层" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">电梯最高层</label>
                <div class="layui-input-block">
                    <input type="number" name="elevatorHightestFloor" placeholder="请输入电梯最高层, 必须大于0" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">呼叫电梯间隔时长/s</label>
                <div class="layui-input-block">
                    <input type="number" name="elevatorCallSpanTime" placeholder="呼叫电梯间隔时长" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="setting">确认保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['form','laydate'], function () {
        var form = layui.form,
            layer = layui.layer,
            laydate = layui.laydate;
        var $ = layui.jquery;
        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        laydate.render(
            {
                elem: "#calibrationEnableStartTime",
                type: "time",
            });
        laydate.render(
            {
                elem: "#calibrationEnableEndTime",
                type: "time",
            });
        form.render();

        //动态添加下拉框     同时可以设置默认值
        $.ajax({
            type: 'get',
            url: 'api/SystemInfo/GetSystemInfo',
            dataType: 'json',
            success: function (res) {
                if (res.code === 200) {
                    var data = res.data;
                    form.val("settingForm",
                        {
                            "ip": data.ip,
                            "port": data.port,
                            "minPower": data.minPower,
                            "maxPower": data.maxPower,
                            "chargePower": data.chargePower,
                            "deliveryUrl": data.deliveryUrl,
                            "completeUrl": data.completeUrl,
                            "availableStatus": data.availableStatus,
                            "isRegionCheck": data.isRegionCheck,
                            "isMaterialCheck": data.isMaterialCheck,
                            "isQuickMatch": data.isQuickMatch,
                            "idleCharginTime": data.idleCharginTime,
                            "idleNotChargePower": data.idleNotChargePower,
                            "isParkControl": data.isParkControl,
                            "enableCalibration": data.enableCalibration,
                            "timeNode": data.timeNode,
                            "calibrationEnableStartTime": data.calibrationEnableStartTime,
                            "calibrationEnableEndTime": data.calibrationEnableEndTime,
                            "calibrationSpan": data.calibrationSpan,
                            "hasElevator": data.hasElevator,
                            "elevatorIP": data.elevatorIP,
                            "elevatorLowestFloor": data.elevatorLowestFloor,
                            "elevatorHightestFloor": data.elevatorHightestFloor,
                            "elevatorCallSpanTime": data.elevatorCallSpanTime
                        });
                }
            }
        });

        //监听提交
        form.on('submit(setting)', function (data) {

            data.field.availableStatus = data.field.availableStatus.split(',');
            console.log(data.field.availableStatus);
            data.field.isRegionCheck = data.field.isRegionCheck == "on";
            data.field.isMaterialCheck = data.field.isMaterialCheck == "on";
            data.field.isParkControl = data.field.isParkControl == "on";
            data.field.isQuickMatch = data.field.isQuickMatch == "on";
            data.field.enableCalibration = data.field.enableCalibration == "on";
            data.field.hasElevator = data.field.hasElevator == "on";

            $.ajax({
                url: 'api/SystemInfo/UpdateSettingInfo',
                method: 'post',
                contentType: 'application/json; charset=utf-8',
                cache: false,
                data: JSON.stringify(data.field),
                success: function (res) {

                    if (res.code === 200) {
                        var index = layer.confirm('修改成功!', {icon:1});
                    }
                    else
                        layer.msg('添加失败!', { icon: 2 });
                },
                error: function (data) {
                    layer.msg('添加出错!', { icon: 2 });

                }
            });
            return false;
        });

    });
</script>